statefiles: fix stale pio handling for !ubus
authorDavid Härdeman <[email protected]>
Sun, 30 Nov 2025 22:13:39 +0000 (23:13 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Tue, 9 Dec 2025 15:38:32 +0000 (16:38 +0100)
Currently, config.c:odhcpd_reload() will call:
set_config()
// the piodir is set here
set_interface()
config_parse_interface()
statefiles_read_prefix_information()
statefiles_setup_dirfd()
ubus_apply_network()
config_parse_interface()
statefiles_read_prefix_information()

This works when ubus is enabled, because of the extra call to
ubus_apply_network() which will read the pio file after the
dirfd has been set up.

However, it won't work when ubus isn't enabled since it'll
turn ubus_apply_network() into a noop.

Fix this by moving the statefiles_setup_dirfd() calls into
set_config(), i.e. setup the dirfds as soon as the relevant
cfg options have been read.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/333
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/config.c

index a79284c7e48f03805298e55857c2faf0948706f5..cb971fd961e30e6ea30614ec0f54318c71089ac3 100644 (file)
@@ -492,6 +492,17 @@ static void set_config(struct uci_section *s)
        if ((c = tb[ODHCPD_ATTR_ENABLE_TZ]))
                config.enable_tz = blobmsg_get_bool(c);
 
+       if (config.dhcp_statefile) {
+               char *dir = dirname(strdupa(config.dhcp_statefile));
+               char *file = basename(config.dhcp_statefile);
+
+               memmove(config.dhcp_statefile, file, strlen(file) + 1);
+               statefiles_setup_dirfd(dir, &config.dhcp_statedir_fd);
+       } else {
+               statefiles_setup_dirfd(NULL, &config.dhcp_statedir_fd);
+       }
+       statefiles_setup_dirfd(config.dhcp_hostsdir, &config.dhcp_hostsdir_fd);
+       statefiles_setup_dirfd(config.ra_piodir, &config.ra_piodir_fd);
 }
 
 static void sanitize_tz_string(const char *src, uint8_t **dst, size_t *dst_len)
@@ -2082,18 +2093,6 @@ void odhcpd_reload(void)
        }
        uci_unload(uci, system);
 
-       if (config.dhcp_statefile) {
-               char *dir = dirname(strdupa(config.dhcp_statefile));
-               char *file = basename(config.dhcp_statefile);
-
-               memmove(config.dhcp_statefile, file, strlen(file) + 1);
-               statefiles_setup_dirfd(dir, &config.dhcp_statedir_fd);
-       } else {
-               statefiles_setup_dirfd(NULL, &config.dhcp_statedir_fd);
-       }
-       statefiles_setup_dirfd(config.dhcp_hostsdir, &config.dhcp_hostsdir_fd);
-       statefiles_setup_dirfd(config.ra_piodir, &config.ra_piodir_fd);
-
        vlist_flush(&lease_cfgs);
 
        ubus_apply_network();